
function addPreZero(num){
  if(num<10){
   return '000'+num;
  }else if(num<100){
   return '00'+num;
  }else if(num<1000){
   return '0'+num;
  }else{
   return num;
  }
 }
function sjs() {
  var r = Math.floor(Math.random() * 256); 
  var g = Math.floor(Math.random() * 256); 
  var b = Math.floor(Math.random() * 256); 
  // ctx.strokeStyle='rgb('+ r+','+g+','+b +')';
  return 'rgb('+ r+','+g+','+b +')';
}
//删除数组中指定值
function deleteArr(i){
　　var index = arr.indexOf(i);
    arr.splice(index, 1)
}

 var wordRandomVal ="";
 var aTotal = [];
$(function(){

  var wordImg = $("#wordImg");
  var wordCont = $("#wordCont");
  // var random = Math.floor(Math.random()*wordArr[selectId].word.length);
  // wordData = wordArr[selectId].word[random].word_name;
  // wordContent = wordArr[selectId].word[random].content;
  console.log(wordArr.length)
  for (let index = 0; index < wordArr.length; index++) {
    aTotal.push(index)
  }
  // <img src="./images/1000/" alt=""></img>
  function randomNumber(param) {  
    // return Math.floor(Math.random()*wordArr[selectId].word.length);
    // console.log(wordArr.length+'wordArr.length')
    var randoms = Math.floor(Math.random()*wordArr.length);
    console.log(randoms)
    console.log(aTotal)
    var random = aTotal[randoms];
    // var aTotalIndex = aTotal.indexOf(randoms);
    // aTotal.splice(aTotalIndex, 1)
    // console.log(random)
    // console.log(aTotal)
    wordRandomVal = random;
    console.log(random)
    // wordData = wordArr[random].word_name;
    word = wordArr[random].word;
    tense = wordArr[random].tense;
    wordExample = wordArr[random].example;
    // console.log(sjs())
    wordCont.css("color",sjs()).html(tense);
    // console.log(addPreZero(random+1))
    // var imgHtml = '<p style="color:'+sjs()+'">'+ENExplain+'</p> <img src="./images/1000/'+addPreZero(random+1)+'.jpg" alt=""></img>';
    var liHmtl = '';
    wordExample.forEach(function(item,index){
      liHmtl += '<li><h3>'+item.sentence+'</h3><span>'+item.explain+'</span></li>'
    })
    

    var imgHtml = '<h1 style="color:'+sjs()+'">'+word+'</h1><p style="color:'+sjs()+'">'+tense+'</p><ul>'+liHmtl+'</ul>';
    wordImg.html(imgHtml)
  }
  $("#next").click(function(){

    randomNumber()
  })
  $("#show").click(function(){
    wordImg.find("p").show();
  })
  randomNumber()
})